﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>新闻显示</title>
    <link href="~/EasyUI/themes/icon.css" rel="stylesheet" />
    <link href="~/EasyUI/themes/default/easyui.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="~/EasyUI/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.validate.min.js"></script>

    <script src="~/Scripts/Showdatetime.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.msgProcess.js"></script>

    <script type="text/javascript">
        $(function () {

            $("#btnserch").click(function () {
                $('#tbList').datagrid('load', {
                    keyword: $('#txtkey').val()
                });
            })

            $('#editWindow').window('close');

            $("#tbList").datagrid({
                width: 'auto',
                height: 'auto',
                fitColumns: true,
                striped: true,
                singleSelect: true,
                url: '/admin/Shop/DataList',
                //queryParams:{},
                loadMsg: '数据加载中请稍后……',
                pagination: true,//启用分页，默认每页10行
                rownumbers: false,//显示行号.
                pageSize: 10,//设置 页容量为 5
                pageList: [10, 20, 50],//设置 页容量下拉框
                columns: [[

                    { field: 'ID', title: 'ID', width: 30 },
                    { field: 'ShopName', title: '店名', width: 150 },
                    {
                        field: 'Createtime', title: '联盟日期', width: 120, formatter: function (value) {
                            if (value !=null) {
                                var aa = eval('new ' + (value.replace(/\//g, '')));
                                return aa.format("yyyy-MM-dd");
                            }
                            return '';
                         
                        }
                    }, 
                    { field: 'OrderNum', title: '排序', width: 50 },
                    { field: 'Bz', title: '备注', width: 50 },
                ]],
                toolbar: [{
                    iconCls: 'icon-add',
                    text: "新增",
                    handler: addRow
                }, '-', {
                    iconCls: 'icon-remove',
                    text: "删除",
                    handler: removeRow
                }, '-', {
                    iconCls: 'icon-edit',
                    text: "编辑",
                    handler: editRow
                }],
                onSelect: function (rowI, rowD) {
                    selectedRowIndex = rowI;//将选中行的下标 设置给全局变量
                },
                onDblClickRow: function () {
                    editRow();
                }
            });
        })

        //选中行的下标
        var selectedRowIndex = -1;


        //编辑按钮方法
        function editRow() {
            //获取选中行里的数据！


            var rowData = $("#tbList").datagrid("getSelected");
            if (rowData) {
                $('#editWindow').window('open');
                $('#editWindow').window({
                    draggable: true,
                    title: "编辑"
                });
                $.get("/admin/Shop/EditPage?id=" + rowData.ID + "&t=" + new Date().getTime(), null, function (jsonObj) {
                    if (jsonObj.Statu)
                        $.procAjaxData(jsonObj);
                    else
                        $("#editWindow").html(jsonObj);

                });
            }


        }

        //新增按钮方法
        function addRow() {
            $('#editWindow').window('open');
            $('#editWindow').window({
                draggable: true,
                title: "新增"
            });

            $.get("/admin/Shop/AddPage/?t=" + new Date().getTime(), null, function (jsonObj) {
                if (jsonObj.Statu)
                    $.procAjaxData(jsonObj);
                else
                    $("#editWindow").html(jsonObj);

            });


        }

        //删除方法
        function removeRow() {
            //获取选中行里的数据！
            var rowData = $("#tbList").datagrid("getSelected");
            if (rowData) {
                $.post("/admin/Shop/Del", "id=" + rowData.id, function (jsonObj) {
                    $.procAjaxData(jsonObj, function () {
                        $("#tbList").datagrid("reload");//删除成功后 刷新页面
                    });
                }, "JSON");
            }
        }


    </script>
</head>
<body>

    <div style=" margin:15px 0px 20px 50px">
        关键字：<input id="txtkey" type="text" /> &nbsp; &nbsp;
        <input id="btnserch" type="button" value="搜索" />

    </div>
    <table id="tbList" style="width:auto;height:auto"></table>

    <div id="editWindow" class="easyui-window" title="My Window" style="width:600px;height:400px;"
         data-options="iconCls:'icon-save',modal:true">

    </div>
</body>
</html>